var workConSearch_searchArea="";
var workConSearch_searchPost="";
//add by jianghaibo 2015-05-22
var workConViewSearch_reviewState="";
var workConViewSearch_empName="";
var workConViewSearch_startDate="";
var workConViewSearch_endDate="";
var workConViewSearch_isSearch="";
var userPostId="";
var viewType="";

var pageNo=null;
$( document ).on( "pageshow", "#workConViewList", function( event ) {
	workConSearch_searchArea=getParameterByName("searchArea", getLocationUrl(event) );
	workConSearch_searchPost=getParameterByName("searchPost", getLocationUrl(event) );
	//add by jianghaibo 2015-05-22
	workConViewSearch_reviewState=getParameterByName("searchReviewState", getLocationUrl(event) );
	workConViewSearch_empName=getParameterByName("searchEmpName", getLocationUrl(event) );
	workConViewSearch_startDate=getParameterByName("searchStartDate", getLocationUrl(event) );
	workConViewSearch_endDate=getParameterByName("searchEndDate", getLocationUrl(event) );
	workConViewSearch_isSearch=getParameterByName("isSearch", getLocationUrl(event) );
	userPostId = getParameterByName("userPostId", getLocationUrl(event) );
	viewType = getParameterByName("viewType", getLocationUrl(event) );
	//alert("workConViewSearch_reviewState---"+workConViewSearch_reviewState+"#workConViewSearch_empName---"+workConViewSearch_empName+"#workConViewSearch_startDate-----"+workConViewSearch_startDate+"#workConViewSearch_endDate"+workConViewSearch_endDate);
	pageNo= isNullOrEmpty(pageNo)? "1" : pageNo;
	pageSize="10";
	$("#wrapper_workConViewList  #pullDown").hide();
	$("#wrapper_workConViewList  #pullUp").hide();
//	if(userPostId=="S"){
//		$("#workConList_back").show();
//	}else{
//		$("#workConList_back").hide();
//	}
	
	var scrollObj_workConViewList=scrollPlugLoadedOfReturn_new("wrapper_workConViewList",
			function() {
				setTimeout(function () {
//					alert(pageNo +"===="+ totalPage);
					if(pageNo <= totalPage){
						pageNo++;
						loadData_workConViewList(false,scrollObj_workConViewList);
					}else{
						$("#wrapper_workConViewList  #pullUp").hide();
					}
					
				}, 1000);	
			},
			function() {
				setTimeout(function () {
					if(pageNo>1){
						pageNo--;
						loadData_workConViewList(true,scrollObj_workConViewList);
						if(pageNo==1){
							$("#wrapper_workConViewList  #pullDown").hide();
						}
					}else{
						$("#wrapper_workConViewList  #pullDown").hide();
					}
				}, 1000);
			});
	
	loadData_workConViewList(true,scrollObj_workConViewList);
	
	
});
$( document ).on( "pagecreate", "#workConViewList", function( event ) {
	access_token=getParameterByName("access_token", getLocationUrl(event) );
	thisWorkConType = getParameterByName("workConType", getLocationUrl(event) );
	pageNo = getParameterByName("pageNo", getLocationUrl(event) );
	userPostId = getParameterByName("userPostId", getLocationUrl(event) );
	viewType = getParameterByName("viewType", getLocationUrl(event) );
	all_e=event;
	if(thisWorkConType == 3){
		workConType = '1';
	}else{
		workConType = thisWorkConType;
	}
//	if(userPostId=="S"){
//		$("#workConList_back").show();
//	}else{
//		$("#workConList_back").hide();
//	}
	if(thisWorkConType=="2"||thisWorkConType=="3"||thisWorkConType=="5"){
		$("#workConList_back").hide();
	}

	//去 我的日志
	$("#workConViewList_myWorkLog").on('click', function () {
		goTo2(rootPath+"/jsp/weixin/workConList.jsp?access_token="+access_token+"&workConType="+thisWorkConType+"&userPostId="+userPostId,false);
	});
	if( !isNullOrEmpty(workConType) && workConType=="2"){
		//去 日志分享
		$("#workConViewList_shareBtn").show().on('click', function () {
			goTo2(rootPath+"/jsp/weixin/workConShareList.jsp?access_token="+access_token+"&workConType="+thisWorkConType+"&userPostId="+userPostId,false);
		});
		//去 特别关注
		$("#workConViewList_careBtn").show().on('click', function () {
			goTo2(rootPath+"/jsp/weixin/workConCareList.jsp?access_token="+access_token+"&workConType="+thisWorkConType+"&userPostId="+userPostId,false);
		});
		
		//去 日志检索页面
		$("#workConViewList_goSearchPage").show().on('click', function () {
			goTo2(rootPath+"/jsp/weixin/workConSearch.jsp?access_token="+access_token+"&workConType="+thisWorkConType+"&userPostId="+userPostId,false);
		});
	}
	//add by jianghaibo 201-05-22
	else if( !isNullOrEmpty(workConType) && workConType=="1"){
		//去 日志检索页面
		$("#workConViewList_goSearchPage").show().on('click', function () {
			goTo2(rootPath+"/jsp/weixin/workConViewSearch.jsp?access_token="+access_token+"&workConType="+thisWorkConType+"&userPostId="+userPostId+"&viewType="+viewType,false);
		});
	}
	//查看所有B类的日志
	else if( !isNullOrEmpty(workConType) && workConType=="4"){
		//去 日志检索页面
		$("#workConViewList_goSearchPage").show().on('click', function () {
			goTo2(rootPath+"/jsp/weixin/workConViewSearch.jsp?access_token="+access_token+"&workConType="+thisWorkConType+"&userPostId="+userPostId+"&viewType="+viewType,false);
		});
	}
	
});
/**
 * 
 * @param isFresh 是否刷新
 * @param isFresh 是否初始列表
 */
function loadData_workConViewList(isFresh,scrollObj_workConViewList){
	showLoading();
	$.ajax({
	  	url: rootPath+"/workCon/workConViewList.do",
	  	type: "POST",
	  	dataType: "text",
		data: "access_token="+access_token+"&workConType="+thisWorkConType+"&pageNo="+pageNo+"&pageSize="+pageSize
			+"&searchPost="+workConSearch_searchPost+"&searchArea="+workConSearch_searchArea
			//add by jianghaibo 2015-05-22 
			+"&searchConState="+workConViewSearch_reviewState+"&searchEmpName="+workConViewSearch_empName
			+"&searchConStartTime="+workConViewSearch_startDate+"&searchConEndTime="+workConViewSearch_endDate
			+"&isSearch="+workConViewSearch_isSearch+"&userPostId="+userPostId+"&viewType="+viewType,
	  	success: function( response ) {
	  		hideLoading();
	  		var data=$.parseJSON(response);
			if(data.state=="200"){
				totalPage=data.data.totalPage;
		  		var totalRow=data.data.totalRow;
		  		var arr=data.data.rows;
				var content = "";
				var sideStyle1="style=\'right:5px; \'";
				margin_top_6="style='margin-top:6px;width: 80%; display: inline-block;' ";
				
				for (var i=0;i<arr.length;i++){
					var toPage=rootPath+"/jsp/weixin/workConInfo.jsp?toWorkConId="+arr[i].id+"&access_token="+access_token+"&workConType="+thisWorkConType+"&isReview=true"+"&pageNo="+pageNo
						+"&searchReviewState="+workConViewSearch_reviewState+"&searchEmpName="+workConViewSearch_empName 
						+"&searchStartDate="+workConViewSearch_startDate+"&searchEndDate="+workConViewSearch_endDate+"&userPostId="+userPostId+"&viewType="+viewType;//去日志查看页
					var toOtherLogPage=rootPath+"/jsp/weixin/workConListOfOthers.jsp?toWorkConId="+arr[i].id+"&fromPage=workConViewList"+"&access_token="+access_token+"&workConType="+thisWorkConType+"&pageNo="+pageNo+"&userPostId="+userPostId+"&viewType="+viewType;
					var headerPic=rootPath+defaultHeadPic;
					if(arr[i].headImageUrl!=undefined && arr[i].headImageUrl!="" )
						headerPic=arr[i].headImageUrl;
					var name=arr[i].empName;
					var bg_color="c_blue";
					var posiName=arr[i].posiName;
					var reviewState="待审阅";
					if(arr[i].reviewState == "2"){//已审阅 //  <img  '+imgStyle+' src="'+headerPic+'" class="ui-li-icon">
						bg_color="c_yellow";
						reviewState="已审阅";
					}
					if(arr[i].reviewState == "3"){//已审阅 //  <img  '+imgStyle+' src="'+headerPic+'" class="ui-li-icon">
						bg_color="c_red";
						reviewState="已批示";
					}
					var str =arr[i].log_date; 
					if(isNullOrEmpty(str)) str="";
					if(str!=""){ str = str.replace(/-/g,"/"); var date = new Date(str );var month=date.getMonth()+1;var day=date.getDate();str=month+"月"+day+"日：";}
					var orgName='<span style="font-size:12px;">('+arr[i].orgName+')</span>';
					if( !isNullOrEmpty(workConType) && workConType=="2"){
						content +='<li data-icon="false">\
						  <a href="#"    '+comStyle+'>\
						  	<img  '+imgStyle+' src="'+headerPic+'" class="ui-li-icon" onClick="goTo2(\''+toOtherLogPage+'\',false)">\
							<p '+margin_top_no+' onClick="goTo2(\''+toPage+'\',false)"><span style="font-size:15px;">'+name+orgName+'</span><strong class="ui-li-aside_fresh" '+sideStyle1+' >'+arr[i].create_time+'</strong></p>\
							<p '+margin_top_6+' name=\'whiteSpace'+pageNo+'\' onClick="goTo2(\''+toPage+'\',false)"><span style="width:80%">'+str+arr[i].workcon1+'</span><span class="reviewFlag '+bg_color+' " >'+posiName+'</span></p>\
						  </a>\
						</li>';
					}
					else if( !isNullOrEmpty(workConType) && workConType=="4"){
						content +='<li data-icon="false">\
							  <a href="#"    '+comStyle+'>\
							  	<img  '+imgStyle+' src="'+headerPic+'" class="ui-li-icon" onClick="goTo2(\''+toOtherLogPage+'\',false)">\
								<p '+margin_top_no+' onClick="goTo2(\''+toPage+'\',false)"><span style="font-size:15px;">'+name+orgName+'</span><strong class="ui-li-aside_fresh" '+sideStyle1+' >'+arr[i].create_time+'</strong></p>\
								<p '+margin_top_6+' name=\'whiteSpace'+pageNo+'\' onClick="goTo2(\''+toPage+'\',false)"><span style="width:80%">'+str+arr[i].workcon1+'</span><span class="reviewFlag '+bg_color+' " >'+reviewState+'</span></p>\
							  </a>\
							</li>';
					}
					else{
						content +='<li data-icon="false">\
							  <a href="#"    '+comStyle+'>\
							  	<img  '+imgStyle+' src="'+headerPic+'" class="ui-li-icon" onClick="goTo2(\''+toOtherLogPage+'\',false)">\
								<p '+margin_top_no+' onClick="goTo2(\''+toPage+'\',false)"><span style="font-size:15px;">'+name+'</span><strong class="ui-li-aside_fresh" '+sideStyle1+' >'+arr[i].create_time+'</strong></p>\
								<p '+margin_top_6+' name=\'whiteSpace'+pageNo+'\' onClick="goTo2(\''+toPage+'\',false)"><span style="width:80%">'+str+arr[i].workcon1+'</span><span class="reviewFlag '+bg_color+' " >'+reviewState+'</span></p>\
							  </a>\
							</li>';
					}
				}
				if(arr.length<pageSize){
					$("#wrapper_workConViewList  #pullUp").hide();
				}else{
					$("#wrapper_workConViewList  #pullUp").show();
				}
				if(isFresh)
					$("#thelist_workConViewList").html("");
				
				//页数是2的倍数时，清空缓存列表
				if(pageNo%3==0){
					$("#wrapper_workConViewList  #pullDown").show();
					$("#thelist_workConViewList").html("");
					$("#thelist_workConViewList").append(content).listview('refresh');
				}else{
					$("#thelist_workConViewList").append(content).listview('refresh');
				}
				scrollObj_workConViewList.refresh();
//				$("[name='whiteSpace"+pageNo+"']").on("tap",function (){
//					p_show(this);
//				});
			}else{
				alert_wx('fail',data.msg);
			}
	  	}
	});
}

function goBack(){
	var access_token1=getParameterByName("access_token", getLocationUrl(event) );
	var userPostId1 = getParameterByName("userPostId", getLocationUrl(event) );
	var thisWorkConType1 = getParameterByName("workConType", getLocationUrl(event) );
	goTo2(rootPath+"/jsp/weixin/workConViewSList.jsp?access_token="+access_token1+"&workConType="+thisWorkConType1+"&userPostId="+userPostId1,false);
}

			